package com.sbio.udiapp.util;

import com.sbio.udiapp.net.bean.AjaxResult;

import java.util.function.Supplier;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;


public class ApiServiceUtil {

    public static void enqueue(Supplier<Call<AjaxResult>> supplier, Callback<AjaxResult> resultCall) {
        supplier.get().enqueue(new Callback<AjaxResult>() {
            @Override
            public void onResponse(Call<AjaxResult> call, Response<AjaxResult> response) {
                if (!response.isSuccessful()) {
                    ToastUtil.show("服务器异常，请稍后重试");
                    return;
                }
                resultCall.onResponse(call,response);
            }

            @Override
            public void onFailure(Call<AjaxResult> call, Throwable t) {
                resultCall.onFailure(call,t);
            }
        });
    }
}
